import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter 文本和按钮示例',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key}) : super(key: key);

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  void _onPressed() {
    print('按钮被点击');
    // 这里可以添加按钮点击后的逻辑
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('文本和按钮示例'),
      ),
      body: Padding(
        padding: const EdgeInsets.all(16.0),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            // 示例 1: 基本文本对齐
            const Text(
              "Hello world",
              textAlign: TextAlign.left,
              style: TextStyle(fontSize: 20),
            ),
            
            const SizedBox(height: 20),
            
            // 示例 2
            Text(
              "Hello world! I'm Jack. " * 4,
              maxLines: 1,
              overflow: TextOverflow.ellipsis,
              style: TextStyle(fontSize: 16),
            ),
            
            const SizedBox(height: 20),
            
            // 示例 3: 文本缩放
            const Text(
              "Hello world",
              textScaleFactor: 1.5,
              style: TextStyle(fontSize: 16),
            ),
            
            const SizedBox(height: 40),
            
            // 示例 4: 带图标的 ElevatedButton
            ElevatedButton.icon(
              icon: const Icon(Icons.send),
              label: const Text("发送"),
              onPressed: _onPressed,
            ),
            
            const SizedBox(height: 20),
            
            // 示例 5: 带图标的 OutlinedButton
            OutlinedButton.icon(
              icon: const Icon(Icons.add),
              label: const Text("添加"),
              onPressed: _onPressed,
            ),
            
            const SizedBox(height: 20),
            
            // 示例 6: 带图标的 TextButton
            TextButton.icon(
              icon: const Icon(Icons.info),
              label: const Text("详情"),
              onPressed: _onPressed,
            ),
          ],
        ),
      ),
    );
  }
}


